//
//  MainXMLParser.m
//  Mehfile Zainab
//
//  Created by Sitara Badourali on 30/11/12.
//  Copyright (c) 2012 Sitara Badourali. All rights reserved.
//

#import "MainXMLParser.h"
#import "SplashScreenViewController.h"
#import "URLDataRequester.h"

@implementation MainXMLParser

@synthesize URLToLoad;

- (MainXMLParser *) initXMLParser:(SplashScreenViewController*)aViewController {
    
    [super init];
    
    viewController = aViewController;
    
    currentElementValue = [[NSMutableString alloc]init];
    
    return self;
}


- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
    attributes:(NSDictionary *)attributeDict {
    
    //NSLog(@"Processing Element: %@", elementName);
    
}


- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
    
    [currentElementValue appendString:[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
    
}



- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
    
    if([elementName isEqualToString:@"image"]) {
        URLToLoad = currentElementValue;
        NSLog(@"Image to load in cache : %@", URLToLoad);
        //[viewController loadDataWithURL:[NSURL URLWithString:URLToLoad]];
        URLDataRequester *requester = [[URLDataRequester alloc] init];
        [requester loadDataWithURL:[NSURL URLWithString:URLToLoad]];
    }
    
    [currentElementValue release];
    currentElementValue = [[NSMutableString alloc]init];
    
}


- (void) dealloc {
    [currentElementValue release];
    [super dealloc];
}

@end
